#include <iostream>
using namespace std;
//int n,m,ll,vv,gg=0,tt=0,bbb=-1,need=1,ttt=0,aly[100001],aly1[100001],bj,bjj,v[100001],a[100001],d[100001],l[100001];
int n,m,ll,vv,gg=0,tt=0,ttt=0,bbb=-1,need=1,bj,bjj;
int aly[100001],aly1[100001],v[100001],a[100001],d[100001],l[100001];
bool jbj=true;
void justdoit()
{
    cin>>n>>m>>ll>>vv;
    for(int i=1;i<=n;i++)
    {
        cin>>d[i]>>v[i]>>a[i];
        if(a[i]==0)
        {
            tt++;
        }
        else if(a[i]>0)
        {
            ttt++;
        }
    }
    for(int i=1;i<=m;i++)
    {
        cin>>l[i];
        if(l[i]>bbb)
            bbb=l[i];
    }
    for(int i=1;i<=n;i++)
    {
        if(tt==n or ttt==n)//tf
        {
            break;
        }
        if(a[i]==0)//exchange
        {
            if(v[i]>vv and d[i]<=bbb)
            {
                gg++;
            }
        }
        else if(a[i]>0)
        {
            if(v[i]*v[i]>vv*vv-2*a[i]*(bbb-d[i]))
            {
                int y=1;
                while(d[i]>l[y])
                {
                    y++;
                }
                while(v[i]*v[i]<=vv*vv-2*a[i]*(l[y]-d[i]))
                {
                    y++;
                }
                gg++;
                aly1[i]=y;
                aly[i]=m;
            }
        }
        else
        {
            if(v[i]>vv)
            {
                int y=1,y1=1;
                while(d[i]>l[y])
                {
                    y++;
                }
                y1=y;
                while(v[i]*v[i]>vv*vv-2*a[i]*(l[y]-d[i]))
                {
                    y++;
                }
                if(y==y1)
                {
                    continue;
                }
                y--;
                gg++;
                aly1[i]=y1;
                aly[i]=y;
            }
        }

    }
    //math
    bj=aly1[1];
    bjj=aly[1];
    for(int j=2;j<=n;j++)
    {
        if(bjj>=aly1[j])
        {
            bj=max(bj,aly1[j]);
            bjj=min(bjj,aly[j]);
        }
        else
        {
            need++;
            bj=aly1[j];
            bjj=aly[j];
        }
    }
    cout<<gg<<" "<<m-need;
    if(tt==n)//tf
    {
       for(int i=1;i<=n;i++)
        {
            if(v[i]>vv and d[i]<=bbb)
            {
                gg++;
            }
        }
        cout<<gg<<" "<<m-1;
    }
    else if(ttt==n)
    {
        for(int i=1;i<=n;i++)
        {
            if(v[i]*v[i]>vv*vv-2*a[i]*(bbb-d[i]))
            {
                gg++;
            }
        }
        cout<<gg<<" "<<m-1;
    }
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int q;
    cin>>q;
    for(int i=1;i<=q;i++)
    {
        justdoit();
        cout<<endl;
    }
    return 0;
}
